package seven.test_7_24;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] arr = new int[n + 1];
        PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        int count = 0;
        for (int i = 0; i < n; i++) {
            int tmp = scanner.nextInt();
            if(arr[tmp] == 0) {
                count++;
            }
            arr[tmp]++;
        }
        for (int i = 1; i <= n; i++) {
            if(arr[i] != 0) {
                pq.add(arr[i]);
            }
        }
        if(count > m) {
            System.out.println(-1);
            return;
        }
        while (pq.size() < m) {
            int max = pq.poll();
            if(max / 2 <= 0) {
                System.out.println(-1);
                return;
            }
            if (max % 2 == 0) {
                max /= 2;
                pq.add(max);
                pq.add(max);
            } else {
                pq.add(max/2);
                max = max / 2 + 1;
                pq.add(max);
            }
        }
        System.out.println(pq.peek());
    }
}

